package com.qf.controller;

import com.qf.VO.ProductBatchesVO;
import com.qf.VO.Stu;
import com.qf.constants.Status;
import com.qf.model.ProductBatches;
import com.qf.model.TTask;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.page.Result;
import com.qf.service.ProductBatchesService;
import com.qf.service.TaskService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductBatchesController {

    @Autowired
    private ProductBatchesService productBatchesService;
    @Autowired
    private TaskService taskService;

    @RequestMapping("all")
    public PageResult all(@RequestBody QueryPageBean queryPageBean){
        return productBatchesService.findPage(queryPageBean);
    }

    /**
     *添加一个type
     * @param deviceType
     * @return result
     */
    @RequestMapping("/add")
    public Result add(@RequestBody ProductBatchesVO productBatchesVO){
        Result result = new Result();
        int i = productBatchesService.add(productBatchesVO);

        if (i>0){
            result.setFlag(Status.SUCCESS.isFlag());
            result.setMessage(Status.SUCCESS.getMessage());
            return result;
        }
        result.setMessage(Status.FAIL.getMessage());
        result.setFlag(Status.FAIL.isFlag());
        return result;
    }

    /**
     * farm回显
     * @param id
     * @return result
     */
    @RequestMapping("findById")
    public Result findById(@RequestParam("id") int id){
        Result result = new Result();
        ProductBatches productBatches = productBatchesService.findById(id);
        if (ObjectUtils.isNotEmpty(productBatches)){
            result.setData(productBatches);
            result.setFlag(Status.SUCCESS.isFlag());
            result.setMessage(Status.SUCCESS.getMessage());
            return result;
        }
        result.setMessage(Status.FAIL.getMessage());
        result.setFlag(Status.FAIL.isFlag());
        return result;
    }

    /**
     * 修改farm
     * @param farm
     * @return result
     */
    @RequestMapping("edit")
    public Result edit(@RequestBody ProductBatches productBatches){
        Result result = new Result();
        int i = productBatchesService.edit(productBatches);
        if (i>0){
            result.setFlag(Status.SUCCESS.isFlag());
            result.setMessage(Status.SUCCESS.getMessage());
            return result;
        }
        result.setMessage(Status.FAIL.getMessage());
        result.setFlag(Status.FAIL.isFlag());
        return result;
    }

    /**
     * 删除user
     * @param id
     * @return result
     */
    @RequestMapping("delete")
    public Result delete(@RequestParam("id") int id){
        Result result = new Result();
        int i = productBatchesService.delete(id);
        if (i>0){
            result.setFlag(Status.SUCCESS.isFlag());
            result.setMessage(Status.SUCCESS.getMessage());
            return result;
        }
        result.setMessage(Status.FAIL.getMessage());
        result.setFlag(Status.FAIL.isFlag());
        return result;
    }




}
